<template>
	<view class="wrapper shenQing">
		<u--form :model="model1" :rules="rules" ref="uForm">
			<u-form-item prop="time">
				<div class="f28 w100 mb40">
					<div class="c333 mb20">举报内容</div>
					<textarea placeholder="请输入举报内容" placeholder-class="c9b f28"></textarea>
				</div>
			</u-form-item>
			<!-- <div class="mt40 mb40 flex-start" @click="model1.ni=!model1.ni">
				<div class="radio bor50" v-if="!model1.ni"></div>
				<image v-else src="../../../static/shouye/success.png" mode="widthFix" class="radio-icon bor50"></image>
				<div class="f28 ml10">是否匿名</div>
			</div> -->
			<div class="mb20">
				<text class="f28">上传图片</text>
				<text class="c9b">（最多6张图片）</text>
			</div>
			<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" :maxCount="6">
				<div class="upload-btn center">
					<image src="../../../static/shouye/upload.png" mode="widthFix" class="upload-icon"></image>
				</div>
			</u-upload>
			<div class="posf">
				<u-button type="primary" @click="submit">确定提交</u-button>
			</div>
		</u--form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				range: ['居民身份证'],
				model1: {
					date: '',
					time: '',
					ni: false
				},
				fileList1: [],
				rules: {
					date: [{
						required: true,
						message: '请选择预约日期',
						trigger: ['blur', 'change']
					}]
				}
			}
		},
		methods: {
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			submit() {
				this.open('./jieGuo')
				this.$refs.uForm.validate().then(res => {
					uni.$u.toast('校验通过')
				}).catch(errors => {
					uni.$u.toast('校验失败')
				})
			}
		}
	}
</script>

<style lang="scss">
	:deep(.u-form-item__body) {
		padding: 0 !important;
	}
	:deep(.u-upload__wrap__preview__image){
		width: 140rpx!important;
		height: 140rpx!important;
		border-radius: 12rpx 12rpx 12rpx 12rpx!important;
	}
	.posf {
		bottom: 120rpx;
		left: 112rpx;
	}

	.upload-btn {
		width: 140rpx;
		height: 140rpx;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		border: 2rpx dashed #9F9F9F;
	}

	.upload-icon {
		width: 45.21rpx;
		height: 45.21rpx;
	}

	.radio-icon {
		width: 34rpx;
		height: 34rpx;
	}

	.radio {
		width: 36rpx;
		height: 36rpx;
		border: 2rpx solid #C9C9C9;
	}

	.shen2-icon {
		width: 40.74rpx;
		height: 33.33rpx;
	}

	textarea {
		height: 290rpx;
		background: #F1F9FE;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		padding: 14rpx 20rpx;
		width: 672rpx;
	}

	.down-icon {
		width: 33.56rpx;
		height: 30.63rpx;
	}

	.input-box {
		height: 68rpx;
		background: #F1F9FE;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		padding: 0 20rpx;
	}

	.c333 {
		width: 130rpx;
	}

	.address-icon {
		width: 23.56rpx;
		height: 30.63rpx;
		top: 5rpx;
	}

	.shen1-icon {
		width: 35.45rpx;
		height: 39.77rpx;
	}

	.shenQing {
		padding: 40rpx;
	}
</style>